Syntax Errors 4 Semantic Errors 0 listingh This file contains the function

Syntax errors 4 semantic errors 0 listingh this file

This preview shows page 6 - 14 out of 21 pages.

Syntax Errors 4
Image of page 6
Semantic Errors 0 ------------------------------------------------------------ listing.h // This file contains the function prototypes for the functions that produce the // compilation listing enum ErrorCategories {LEXICAL, SYNTAX, GENERAL_SEMANTIC, DUPLICATE_IDENTIFIER, UNDECLARED}; void firstLine(); void nextLine(); int lastLine(); void appendError(ErrorCategories errorCategory, string message); ------------------------------------------------------------------------ ---------- makefile
Image of page 7
compile: scanner.o parser.o listing.o g++ -o compile scanner.o parser.o listing.o scanner.o: scanner.c listing.h tokens.h g++ -c scanner.c scanner.c: scanner.l flex scanner.l mv lex.yy.c scanner.c parser.o: parser.c listing.h g++ -c parser.c parser.c tokens.h: parser.y bison -d -v parser.y mv parser.tab.c parser.c mv parser.tab.h tokens.h
Image of page 8
listing.o: listing.cc listing.h g++ -c listing.cc ---------------------------------------------------------- parser.y %{ #include using namespace std; #include "listing.h" int yylex(); void yyerror(const char* message); %} %error-verbose %token IDENTIFIER %token INT_LITERAL
Image of page 9
%token ADDOP MULOP RELOP ANDOP %token BEGIN_ BOOLEAN END ENDREDUCE FUNCTION INTEGER IS REDUCE RETURNS %% function: function_header optional_variable body ; function_header: FUNCTION IDENTIFIER RETURNS type ';' ; optional_variable: variable | ; variable: IDENTIFIER ':' type IS statement_ ; type:
Image of page 10
INTEGER | BOOLEAN ; body: BEGIN_ statement_ END ';' ; statement_: statement ';' | error ';' ; statement: expression | REDUCE operator reductions ENDREDUCE ; operator: ADDOP | MULOP ;
Image of page 11
Image of page 12
factor MULOP primary | primary ; primary: '(' expression ')' | INT_LITERAL | IDENTIFIER ; %% void yyerror(const char* message) { appendError(SYNTAX, message); } int main(int argc, char *argv[]) { firstLine();
Image of page 13
Image of page 14

You've reached the end of your free preview.

Want to read all 21 pages?

  • Fall '19
  • Logic, relational operator, Common operator notation

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture