Programming language. please help(screenshot of the source code and output please) thanks.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899559
Joined: Mon Aug 02, 2021 8:13 am

Programming language. please help(screenshot of the source code and output please) thanks.

Post by answerhappygod »

Programming language. please help(screenshot of the source code
and output please) thanks.
Programming Language Please Help Screenshot Of The Source Code And Output Please Thanks 1
Programming Language Please Help Screenshot Of The Source Code And Output Please Thanks 1 (384.28 KiB) Viewed 73 times
Project: Employ the UNIX utility lex to write a scanner for Subset Pascal whose grammar is given in Table 1. Tokens are defined in Table 2 and Figures 1, 2, 3, and 4. An example program is given in Figure 5 and the corresponding output produced by the Subset Pascal scanner is shown in Figure 6. You are not required to produce an exact replica of the output shown in Figure 6, but you are required to print one line for every token recognized. For each token, you must print its tokencode, its location, the string of characters recognized, and its symbolic name. Project Files: Project Location: On the last page of this document, you can find a sample score sheet used to grade this project Project 1 consists of source files that are identified below. You must name your source files exactly as shown below. Project files must be stored in the root directory of your student account. Failure to store project files in the root directory of your student account will result in a score of zero (0) for this project. File Description p01.cpp File p01.cpp contains functions which process command line arguments and invoke the scanner, repeatedly to find all the tokens in the input source file. pollex.h File p01lex.h defines the interface to the Subset Pascal scanner. po1tkn.h File po1tkn.h contains the list of preprocessor definitions that define token codes. For example, #define PLUS 1 #define MINUS 2 Command Line: pollex. File pollex.l contains functions that accept the tokens of a Subset Pascal program. p01make File polmake contains instructions for program p01. Instructions are written for the UNIX utility make. File p01make creates the executable file p01 from source files identified above. Project 1 can be invoked with zero or one program parameters. The first program parameter is the source file to be analyzed. Sample command lines together with corresponding actions by program p01 are shown below. Boldfaced type indicates data entered at the keyboard by the user. $p01 Enter the source file name: gcd.pas $ p01 gcd.pas The input file name must have the suffix .pas. Input File Name: Input File: The input file can contain any sequence of characters. The scanner recognizes valid Subset Pascal Tokens and rejects invalid tokens. Sample test files are stored in the class directory. You can obtain copies of these files by issuing the following command when signed on to your student account on the department computer. $ cp~tt/cs4023/*.pas.
Output File Name: The output file name has the same prefix as the input file but substitutes the suffix .trc for input file name suffix .pas. For example, if the input file name is gcd.pas, the output file name is gcd.trc. The output file should contain a list of the Subset Pascal tokens. Tokens and associated information is presented as shown in Figure 6. Output File: | Rule No. LHS RHS 1 program program-head program-declarations program-body 2. program-head program id program-parameters; 3 program-declarations declarations subprogram-declarations 4 program-body compound-statement. 5 program-parameters E 6 program-parameters (program-parameter-list) 7 program-parameter-list identifier-list 8 identifier-list id 9 identifier-list → identifier-list , id 10 declarations → e 11 declarations → declarations var identifier-list : type; 12 type → standard-type 13 type array[ intlit .. intlit ] of standard-type 14 standard-type id 15 subprogram-declarations → E 16 subprogram-declarations subprogram-declarations subprogram-declaration; 17 subprogram-declaration subprogram-head declarations compound-statement 18 subprogram-head function id subprogram-parameters: standard-type; 19 subprogram-head procedure id subprogram-parameters; 20 subprogram-parameters E 21 subprogram-parameters (parameter-list) 22 parameter-list identifier-list : type 23 parameter-list parameter-list; identifier-list : type 24 compound-statement begin optional-statements end 25 optional-statements 26 optional-statements → statement-list 27 statement-list statement 28 statement-list statement-list; statement 29 statement variable := expression 30 statement procedure-statement 31 statement alternative-statement 32 statement iterative-statement 33 statement compound-statement Table 1. Subset Pascal Grammar. 1 1 1 E
RHS Id 34 35 36 37 38 39 40 41 42 1 个 = 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Rule LHS alternative-statement →if-statement iterative-statement → while-statement iterative-statement repeat-statement iterative-statement for-statement if-statement if expression then statement else statement while-statement → while expression do statement repeat-statement → repeat statement_list until expression for-statement → for variable := expression to expression do statement for-statement ► for variable := expression downto expression do statement variable id variable id [ expression ] procedure-statement → id procedure-statement -> id (expression-list expression-list expression expression-list → expression-list , expression expression simple-expression expression simple-expression relop simple-expression relop relop relop relop → relop relop >= simple-expression -> term simple-expression sign term sign sign simple-expression simple-expression addop term addop addop addop or term factor term term mulop factor mulop mulop →/ mulop div mulop mod mulop and Table 1. Subset Pascal Grammar (continued). < <= > + 111 + î 63 64 65 66 67 68 69 70 71 * 个 T Rule
Id 72 73 74 75 76 77 78 79 LHS factor factor factor factor factor factor factor factor RHS → id id [ expression-list] id (expression-list ) (expression) → not factor →intlit → realit chrlit Table 1. Subset Pascal Grammar (continued). Comments Blanks Reserve words and identifiers = Tokencodes Token AND ARRAY BEGAN DIV DO DOWNTO ELSE <= >= + Comments are enclosed between { and }. They may not contain a {. Comments may appear after any token. Blanks between tokens are optional, with the exception that reserve words and identifiers must be surrounded by blanks, newline characters, the beginning of the program, or punctuation. Reserve words and identifiers are case-insensitive. For example, Subset Pascal recognizes begin and BeGin as the same token. Capitalization of letters in reserve words and identifiers is ignored. Assign a unique positive integer to each tokencode. Specification Token Specification and EQU array NEQ begin LES div LEQ do GRT downto GEQ else PLUS end MINUS for STAR function SLASH / if ASSIGN mod LPAREN not RPAREN ) of LBRACKET [ or RBRACKET procedure LCURLY { program RCURLY } repeat COLON : then SEMICOLON to COMMA until PERIOD var RANGE while APOSTROPHE Table 2. Subset Pascal Token Definitions * END FOR FUNCTION IF MOD NOT OF OR i PROCEDURE PROGRAM REPEAT THEN TO UNTIL VAR WHILE
id (identifier) letter letter underscore digit underscore Figure 1. id (identifier) . Examples ice_cream • _myclass Principal . intlit (integer literal) digit Figure 2. intlit (integer literal) . Examples: 3 03 6272844 . chrlit (character literal) character Figure 3. chrlit (character literal) Note: A single apostrophe is represented by two apostrophes is succession. Example character literals: 'a' . 1.) . '3' 'begin' 'don''t' . realit (real literal) digit digit ☺ digit Figure 4. realit (real literal) . Examples: 0.6 5E-8 49.22E+08 1E10 .
program example(input,output); var x,y: integer; function gcd(a,b:integer):integer; begin{gcd} if b=0 then ged:=a else ged:=gcd(b,a mod b) end{gcd}; begin{example} readln(x,y); write(gcd(x,y)) end{example} Figure 5. File gcd.pas TI T! Token: Code= 42 Name= PROGRAM liner 1 col= 1 Spelling="program" Token: Code= 50 Name= ID line= 1 col= 9 Spelling="example" Token: Code= 13 Name= LPAREN line- 1 col= 16 Spelling=" (" Token: Code= 50 Name= ID line= 1 col= 17 Spelling="input" Token: Code= 21 Name= COMMA line= 1 col= 22 Spelling=", Token: Code= 50 Name= ID line= 1 col= 23 Spelling="output" Token: Code= 14 Name= RPAREN liner 1 col= 29 Spelling=")" Token: Code= 20 Name= SEMICOLON line= 1 col= 30 Spelling=";" Token: Code= 47 Name= VAR lines 2 col= 3 Spelling="var" Token: Code= 50 Name= ID line= 2 col= 7 Spelling="x" Token: Code= 21 Name= COMMA line= 2 col= 8 Spelling=", Token: Code= 50 Name= ID line= 2 col= 9 Spelling="y" Token: Code= 19 Name= COLON line= 2 col= 10 Spelling=":" Token: Code= 50 Name= ID line= 2 col= 11 Spelling="integer" Token: Code= 20 Name= SEMICOLON line= 2 col= 18 Spelling=";" Token: Code= 35 Name= FUNCTION line= 3 col= 3 Spelling="function" Token: Code= 50 Name= ID line- 3 col= 12 Spelling="god" Token: Code= 13 Name= LPAREN line= 3 col= 15 Spelling=" (" Token: Code= 50 Name= ID line= 3 col= 16 Spelling="a" Token: Code= 21 Name= COMMA line- 3 col= 17 Spelling=", Token: Code= 50 Name= ID lines 3 col= 18 Spelling="b" Token: Code= 19 Name= COLON line- 3 col= 19 Spelling=":" Token: Code= 50 Name= ID lines 3 col= 20 Spelling="integer" Token: Code= 14 Name= RPAREN liner 3 col= 27 Spelling=")" Token: Code= 19 Name= COLON line= 3 col= 28 Spelling=":" Token: Code= 50 Name= ID line- 3 col= 29 Spelling="integer" Token: Code= 20 Name= SEMICOLON line= 3 col= 36 Spelling=";" Token: Code= 28 Name= BEGIN line= 4 col= 3 Spelling="begin" Token: Code= 36 Name= IF line= 5 col= 5 Spelling="if" Token: Code= 50 Name= ID line= 5 col= 8 Spelling="b" Token: Code= 2 Name= EQU line= 5 col= 9 Spelling="=" Token: Code= 51 Name= INTLIT line= 5 col= 10 Spelling="0" Token: Code= 44 Name= THEN line- 5 col= 12 Spelling="then" Token: Code= 50 Name= ID line- 5 col= 17 Spelling="god" Token: Code= 12 Name= ASSIGN line= 5 col= 20 Spelling=":=" Token: Code= 50 Name= ID line= 5 col= 22 Spelling="a" Figure 6. Subset Pascal Scanner output
Token: Code= 32 Name= ELSE line= 6 col= 5 Spelling="else" Token: Code= 50 Name= ID line- 6 col= 10 Spelling="god" Token:Code= 12 Name= ASSIGN line= 6 col= 13 Spelling=":=" Token:Code= 50 Name= ID line= 6 col= 15 Spelling="god" Token:Code= 13 Name= LPAREN liner 6 col= 18 Spelling=" (" Token:Code= 50 Name= ID line= 6 col= 19 Spelling="b" Token:Code= 21 Name= COMMA line= 6 col= 20 Spelling="," Token: Code= 50 Name= ID line= 6 col= 21 Spelling="a" Token: Code= 37 Name= MOD line= 6 col= 23 Spelling="mod" Token: Code= 50 Name= ID line= 6 col= 27 Spelling="b" Token:Code= 14 Name= RPAREN line= 6 col= 28 Spelling=")" Token: Code= 33 Name= END line= 7 col= 3 Spelling="end" Token: Code= 20 Name= SEMICOLON line= 7 col= 11 Spelling=";" Token: Code= 28 Name= BEGIN line= 8 col= 1 Spelling="begin" Token: Code= 50 Name= ID line= 9 col= 3 Spelling="readln" Token: Code= 13 Name= LPAREN line= 9 col= 9 Spelling=" (" Token: Code= 50 Name= ID line- 9 col= 10 Spelling="x" Token:Code= 21 Name= COMMA line= 9 col= 11 Spelling=",' Token:Code= 50 Name= ID lines 9 col= 12 Spelling="y" Token: Code= 14 Name= RPAREN line= 9 col= 13 Spelling=")" Token:Code= 20 Name= SEMICOLON line= 9 col= 14 Spelling=";" Token: Code= 50 Name= ID line= 10 col= 3 Spelling="write" Token:Code= 13 Name= LPAREN line= 10 col= 8 Spelling=" (" Token:Code= 50 Name= ID line= 10 col= 9 Spelling="god" Token:Code= 13 Name= LPAREN line= 10 col= 12 Spelling=" (" Token:Code= 50 Name= ID line= 10 col= 13 Spelling="x" Token: Code= 21 Name= COMMA line= 10 col= 14 Spelling="," Token: Code= 50 Name= ID line= 10 col= 15 Spelling="y" Token: Code= 14 Name= RPAREN line= 10 col= 16 Spelling=")" Token: Code= 14 Name= RPAREN line= 10 col= 17 Spelling=")" Token: Code= 33 Name= END line= 11 col= 1 Spelling="end" Token: Code= 22 Name= PERIOD line= 11 col= 13 Spelling="." Figure 6. Subset Pascal Scanner output (continued)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply