Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shen, Siran
wacc
Commits
549a71f0
Commit
549a71f0
authored
Feb 17, 2021
by
Tom Zhao
Browse files
xz1919: added progressive pipeline scripts
parent
d4b85120
Changes
61
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
549a71f0
...
...
@@ -40,13 +40,13 @@ test-parser-semantic-err:
test-semantics-check-syntax-valid
:
stage
:
test
script
:
-
echo "Using valid examples to test
frontend.
SemanticChecker, should NOT generate any semantics error"
-
echo "Using valid examples to test SemanticChecker, should NOT generate any semantics error"
-
make
-
./scripts/semanticCheckerValid
test-semantics-check-semantic-err
:
stage
:
test
script
:
-
echo "Using invalid examples with only semantic error to test
frontend.
SemanticChecker, SHOULD generate any semantics error and NOT syntax error"
-
echo "Using invalid examples with only semantic error to test SemanticChecker, SHOULD generate any semantics error and NOT syntax error"
-
make
-
./scripts/semanticCheckerSemanticErr
\ No newline at end of file
README
View file @
549a71f0
...
...
@@ -14,7 +14,7 @@ details below).
> lib <
The lib directory contains the ANTLR library files in
frontend.
antlr-4.9.1-complete.jar.
The lib directory contains the ANTLR library files in antlr-4.9.1-complete.jar.
You should not need to make any changes in this directory.
> src <
...
...
@@ -48,15 +48,15 @@ Using the provided scripts
This script takes a pair of ANTLR lexer and parser configuration files (set
within the script) and creates the corresponding Java classes that you can use
in your compiler. The Java files are written to the src/
frontend.
antlr directory and
in your compiler. The Java files are written to the src/antlr directory and
should not be modified by hand. By default this script is set up to generate a
parse tree and a listerner pattern for traversing this tree, but you can modify
the compilation options within the script if you want to produce different
outputs
Important! - running the antlrBuild script will overwrite the
frontend.
antlr directory in
Important! - running the antlrBuild script will overwrite the antlr directory in
the src directory. We heavily suggest you do not write any of your
code within the src/
frontend.
antlr directory
code within the src/antlr directory
> grun <
...
...
@@ -66,17 +66,17 @@ the TestRig in the project environment. You need to tell it what grammar to use
what rule to start parsing with and what kind of output you want.
For example:
./grun
frontend.
antlr.Basic prog -tokens
./grun antlr.Basic prog -tokens
will run the TestRig using the 'Basic' grammar, starting from the rule for
'prog' and outputting the tokens seen by the lexer. To see how the parser groups
these tokens you can use the -tree or -gui options instead, such as:
./grun
frontend.
antlr.Basic prog -gui
In either case you will need to
frontend.
type in your input program and then close the
./grun antlr.Basic prog -gui
In either case you will need to type in your input program and then close the
input stream with ctrl-D.
Rather than typing your input programs in by hand, you can pass the TestRig a
file to read by piping it in through stdin with
./grun
frontend.
antlr.Basic expr -gui < testfile
./grun antlr.Basic expr -gui < testfile
When using the TestRig in this way you won't need to hit ctrl-D to close the
input stream as the EOF character in the file does this for you.
...
...
@@ -90,7 +90,7 @@ script as the access point to your compiler.
You will need to add the ANTLR jar file to the classpath of your calls to Java
if you want to be able to use any of the built in ANTLR features. You can do
this be setting the -cp option on the command line
e.g. java -cp bin:lib/
frontend.
antlr-4.9.1-complete.jar ...rest of call...
e.g. java -cp bin:lib/antlr-4.9.1-complete.jar ...rest of call...
note that the bin: ensures that the bin directory is still part of your java
classpath.
log/checker_invalid_semantic_error.log
View file @
549a71f0
line 13:4 Symbol x is not found in the current scope of the program
line 12:8 Symbol tru is not found in the current scope of the program
line 12:10 Expected frontend.type BOOLEAN for variable i, while the actual frontend.type is INTEGER
line 13:11 Expected frontend.type CHAR for variable b, while the actual frontend.type is BOOLEAN
line 14:11 Expected frontend.type INTEGER for variable c, while the actual frontend.type is CHAR
line 13:16 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 13:29 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 13:10 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 13:40 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 13:10 Expected frontend.type BOOLEAN for variable x, while the actual frontend.type is INTEGER
line 13:10 Symbol NUMBER is not found in the current scope of the program
line 12:14 Calling fst/snd on uninitialised pair expr is not allowed
line 12:14 Calling fst/snd on uninitialised pair expr is not allowed
line 14:7 Expected types are [Pair<null, null>, Array<null>], but the actual frontend.type is INTEGER
line 13:7 Expected types are [STRING, CHAR, INTEGER], but the actual frontend.type is Pair<INTEGER, INTEGER>
line 12:5 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 13:7 Expected types are [CHAR, INTEGER, STRING], but the actual frontend.type is BOOLEAN
line 15:8 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 15:9 Invalid number of arguments: Expected 2 argument(s), but actual number is 3
line 13:4 Symbol x is not found in the current scope of the program
line 16:2 Symbol f is not found in the current scope of the program
line 13:13 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 13:9 Expected frontend.type INTEGER, but the actual frontend.type is CHAR
line 15:9 Invalid number of arguments: Expected 2 argument(s), but actual number is 1
line 11:0 Symbol f has already been declared in the current scope of the program
line 15:10 Expected frontend.type INTEGER for variable b, while the actual frontend.type is BOOLEAN
line 16:17 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 15:16 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 15:21 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 14:14 Expected frontend.type INTEGER, but the actual frontend.type is CHAR
line 12:13 Expected frontend.type CHAR for variable s, while the actual frontend.type is STRING
line 12:11 Expected frontend.type INTEGER for variable b, while the actual frontend.type is BOOLEAN
Symbol x has already been declared in the current scope of the program
line 12:11 Expected frontend.type BOOLEAN for variable c, while the actual frontend.type is CHAR
line 12:11 Expected frontend.type STRING for variable c, while the actual frontend.type is CHAR
line 12:11 Expected frontend.type CHAR for variable b, while the actual frontend.type is BOOLEAN
line 12:10 Expected frontend.type CHAR for variable i, while the actual frontend.type is INTEGER
line 12:10 Expected frontend.type STRING for variable i, while the actual frontend.type is INTEGER
line 15:2 Symbol x is not found in the current scope of the program
line 12:2 Symbol x is not found in the current scope of the program
line 13:10 Symbol y is not found in the current scope of the program
line 12:10 Expected frontend.type BOOLEAN for variable i, while the actual frontend.type is INTEGER
line 12:11 Expected frontend.type STRING for variable b, while the actual frontend.type is BOOLEAN
line 12:13 Expected frontend.type INTEGER for variable s, while the actual frontend.type is STRING
line 14:10 Symbol NUMBER is not found in the current scope of the program
line 12:13 Expected frontend.type BOOLEAN for variable s, while the actual frontend.type is STRING
line 12:11 Expected frontend.type INTEGER for variable c, while the actual frontend.type is CHAR
line 12:18 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 12:11 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 12:16 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 12:10 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 12:17 Expected frontend.type INTEGER, but the actual frontend.type is BOOLEAN
line 12:10 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 12:20 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 12:10 Expected frontend.type BOOLEAN for variable b, while the actual frontend.type is INTEGER
line 16:10 Expected types are [INTEGER, CHAR, STRING], but the actual frontend.type is Pair<INTEGER, INTEGER>
line 16:14 Expected types are [INTEGER, CHAR, STRING], but the actual frontend.type is Pair<INTEGER, INTEGER>
line 14:10 Expected types are [INTEGER, STRING, CHAR], but the actual frontend.type is Array<INTEGER>
line 14:14 Expected types are [INTEGER, STRING, CHAR], but the actual frontend.type is Array<INTEGER>
line 14:2 Expected frontend.type Array<null>, but the actual frontend.type is STRING
line 12:7 Expected frontend.type INTEGER, but the actual frontend.type is CHAR
line 13:7 Expected frontend.type INTEGER, but the actual frontend.type is CHAR
line 12:2 Call return in main function body
line 12:8 Symbol tru is not found in the current scope of the program
line 12:8 Symbol fals is not found in the current scope of the program
line 12:8 Expected frontend.type BOOLEAN, but the actual frontend.type is INTEGER
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
line 12:7 Incompatible type at ''a''': Expected type INTEGER, but the actual type is CHAR
line 13:7 Incompatible type at 'x'': Expected type INTEGER, but the actual type is CHAR
line 12:2 Call return in main function body is not allowed
log/checker_valid_error.log
View file @
549a71f0
line 27:26 token recognition error at: '.'
line 27:27 extraneous input 'node' expecting '='
log/parse_invalid_syntax_error.log
View file @
549a71f0
line 12:22 mismatched input '+' expecting {'end', ';'}
line 13:10 extraneous input 'fst' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 13:10 extraneous input 'snd' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 15:2 mismatched input 'fi' expecting {'else', ';'}
line 17:0 missing 'fi' at 'end'
line 13:2 mismatched input 'else' expecting {'then', '+', '-', '*', '/', '%', '>', '>=', '<', '<=', '==', '!=', '&&', '||'}
line 12:6 missing '=' at 'true'
line 11:0 missing 'begin' at 'bgn'
line 12:11 token recognition error at: ''\H'
line 12:14 token recognition error at: ''\ne'
...
...
@@ -18,7 +12,10 @@ line 11:10 mismatched input 'end' expecting '='
line 12:11 token recognition error at: ''"'
line 12:13 token recognition error at: ''\ne'
line 14:0 missing 'end' at '<EOF>'
line 12:4 Statement exits after return statement.
line 13:0 mismatched input 'end' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 12:22 mismatched input '"World!"' expecting INT_LITER
line 12:10 extraneous input '*' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'fst', 'snd', 'null', 'newpair', 'call', '(', '[', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 12:4 Other statements exist after function return statement.
line 12:6 missing '=' at '('
line 10:0 Function r2 has not returned or exited properly.
line 10:0 Function f has not returned or exited properly.
...
...
@@ -35,20 +32,23 @@ line 11:0 missing 'begin' at 'int'
line 12:21 mismatched input ')' expecting {'int', 'bool', 'char', 'string', 'pair'}
line 12:3 missing '=' at '('
line 12:12 extraneous input '*' expecting IDENT
line 15:2 mismatched input 'fi' expecting {'else', ';'}
line 17:0 missing 'fi' at 'end'
line 13:2 mismatched input 'else' expecting {'then', '+', '-', '*', '/', '%', '>', '>=', '<', '<=', '==', '!=', '&&', '||'}
line 12:6 missing '=' at 'true'
line 13:10 extraneous input 'fst' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 13:10 extraneous input 'snd' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 12:10 extraneous input '[' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 12:13 extraneous input '0' expecting 'end'
line 13:6 no viable alternative at input 'int='
line 12:13 mismatched input '0' expecting {'end', ';', '+', '-', '*', '/', '%', '>', '>=', '<', '<=', '==', '!=', '&&', '||'}
line 12:10 Integer 2200000000 format not compatible with 32bit int
line 12:11 extraneous input 'A4' expecting 'end'
line 13:0 mismatched input 'end' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'null', '(', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 12:22 mismatched input '"World!"' expecting INT_LITER
line 12:10 extraneous input '*' expecting {BOOL_LITER, CHAR_LITER, STR_LITER, 'fst', 'snd', 'null', 'newpair', 'call', '(', '[', '+', '-', '!', 'len', 'ord', 'chr', INT_LITER, IDENT}
line 13:2 extraneous input 'skip' expecting 'end'
line 11:6 mismatched input ';' expecting {'int', 'bool', 'char', 'string', 'fst', 'snd', 'pair', 'begin', 'skip', 'read', 'free', 'return', 'exit', 'print', 'println', 'if', 'while', IDENT}
line 11:14 extraneous input ';' expecting <EOF>
line 11:12 mismatched input 'end' expecting {'int', 'bool', 'char', 'string', 'fst', 'snd', 'pair', 'begin', 'skip', 'read', 'free', 'return', 'exit', 'print', 'println', 'if', 'while', IDENT}
line 12:7 extraneous input ';' expecting {'int', 'bool', 'char', 'string', 'fst', 'snd', 'pair', 'begin', 'skip', 'read', 'free', 'return', 'exit', 'print', 'println', 'if', 'while', IDENT}
line 12:13 extraneous input '0' expecting 'end'
line 13:6 no viable alternative at input 'int='
line 12:13 mismatched input '0' expecting {'end', ';', '+', '-', '*', '/', '%', '>', '>=', '<', '<=', '==', '!=', '&&', '||'}
line 12:10 Integer 2200000000 format not compatible with 32bit int
line 12:11 extraneous input 'A4' expecting 'end'
line 13:4 missing 'do' at 'skip'
line 12:7 missing '=' at 'false'
line 12:14 missing 'do' at 'doo'
...
...
scripts/parserTestSemanticErr
View file @
549a71f0
#!/bin/sh
INVALID_SEMANTIC_ERR
=
"./src/test/examples/invalid/semanticErr"
INVALID_PARSER_SEMANTIC_ERR_LOG
=
"./log/parse_invalid_semantic_error.log"
INVALID_SEMANTIC_ERR
=(
"./src/test/examples/invalid/semanticErr/exit"
"./src/test/examples/invalid/semanticErr/expressions"
"./src/test/examples/invalid/semanticErr/function"
"./src/test/examples/invalid/semanticErr/if"
"./src/test/examples/invalid/semanticErr/IO"
"./src/test/examples/invalid/semanticErr/multiple"
"./src/test/examples/invalid/semanticErr/pairs"
"./src/test/examples/invalid/semanticErr/print"
"./src/test/examples/invalid/semanticErr/read"
"./src/test/examples/invalid/semanticErr/scope"
"./src/test/examples/invalid/semanticErr/variables"
"./src/test/examples/invalid/semanticErr/while"
)
INVALID_PARSER_SEMANTIC_ERR_LOG
=
"./log/parse_invalid_semantic_error.log"
>
$INVALID_PARSER_SEMANTIC_ERR_LOG
for
file
in
$(
find
$INVALID_SEMANTIC_ERR
-name
"*.wacc"
)
do
./compile
-p
$file
2>>
$INVALID_PARSER_SEMANTIC_ERR_LOG
ret
=
$?
echo
"exit status with parsing only: "
$ret
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
# counters to represent the total number of test files to be processed
TOTAL_COUNT
=
$(
find
${
INVALID_SEMANTIC_ERR
[@]
}
-name
"*.wacc"
|
wc
-l
)
COUNTER
=
0
for
folder
in
${
INVALID_SEMANTIC_ERR
[@]
}
;
do
for
file
in
$(
find
$folder
-name
"*.wacc"
)
do
./compile
-p
$file
2>>
$INVALID_PARSER_SEMANTIC_ERR_LOG
ret
=
$?
echo
"exit status with parsing only: "
$ret
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
grep
"line [0-9]*:[0-9]*"
$INVALID_PARSER_SEMANTIC_ERR_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$INVALID_PARSER_SEMANTIC_ERR_LOG
exit
1
fi
((
COUNTER +
=
1
))
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
finished
\n
"
done
if
grep
"line [0-9]*:[0-9]*"
$INVALID_PARSER_SEMANTIC_ERR_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$INVALID_PARSER_SEMANTIC_ERR_LOG
exit
1
fi
echo
"========================================================================================"
echo
"Test Folder"
$folder
"has been processed"
"(
$COUNTER
/
$((
$TOTAL_COUNT
))
)"
echo
"========================================================================================"
done
\ No newline at end of file
scripts/parserTestSynErr
View file @
549a71f0
#!/bin/sh
INVALID_SYNTAX_ERR
=
"./src/test/examples/invalid/syntaxErr"
INVALID_PARSER_SYNTAX_ERR_LOG
=
"./log/parse_invalid_syntax_error.log"
INVALID_SYNTAX_ERR
=(
"./src/test/examples/invalid/syntaxErr/array"
"./src/test/examples/invalid/syntaxErr/basic"
"./src/test/examples/invalid/syntaxErr/expressions"
"./src/test/examples/invalid/syntaxErr/function"
"./src/test/examples/invalid/syntaxErr/if"
"./src/test/examples/invalid/syntaxErr/pairs"
"./src/test/examples/invalid/syntaxErr/print"
"./src/test/examples/invalid/syntaxErr/sequence"
"./src/test/examples/invalid/syntaxErr/variables"
"./src/test/examples/invalid/syntaxErr/while"
)
INVALID_PARSER_SYNTAX_ERR_LOG
=
"./log/parse_invalid_syntax_error.log"
>
$INVALID_PARSER_SYNTAX_ERR_LOG
for
file
in
$(
find
$INVALID_SYNTAX_ERR
-name
"*.wacc"
)
do
./compile
$file
2>>
$INVALID_PARSER_SYNTAX_ERR_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
100
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
!
grep
"line [0-9]*:[0-9]*"
$INVALID_PARSER_SYNTAX_ERR_LOG
>
/dev/null
;
then
echo
"expecting error but found none:"
exit
1
fi
# counters to represent the total number of test files to be processed
TOTAL_COUNT
=
$(
find
${
INVALID_SYNTAX_ERR
[@]
}
-name
"*.wacc"
|
wc
-l
)
COUNTER
=
0
for
folder
in
${
INVALID_SYNTAX_ERR
[@]
}
;
do
for
file
in
$(
find
$folder
-name
"*.wacc"
)
do
./compile
$file
2>>
$INVALID_PARSER_SYNTAX_ERR_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
100
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
!
grep
"line [0-9]*:[0-9]*"
$INVALID_PARSER_SYNTAX_ERR_LOG
>
/dev/null
;
then
echo
"expecting error but found none:"
exit
1
fi
((
COUNTER +
=
1
))
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
finished
\n
"
done
echo
"========================================================================================"
echo
"Test Folder"
$folder
"has been processed"
"(
$COUNTER
/
$((
$TOTAL_COUNT
))
)"
echo
"========================================================================================"
done
\ No newline at end of file
scripts/parserTestValid
View file @
549a71f0
#!/bin/sh
VALID_EXAMPLES
=
"./src/test/examples/valid"
VALID_PARSER_EXAMPLES_LOG
=
"./log/parse_valid_error.log"
VALID_EXAMPLES
=(
"./src/test/examples/valid/advanced"
"./src/test/examples/valid/array"
"./src/test/examples/valid/basic"
"./src/test/examples/valid/expressions"
"./src/test/examples/valid/function"
"./src/test/examples/valid/if"
"./src/test/examples/valid/IO"
"./src/test/examples/valid/pairs"
"./src/test/examples/valid/runtimeErr"
"./src/test/examples/valid/scope"
"./src/test/examples/valid/sequence"
"./src/test/examples/valid/variables"
"./src/test/examples/valid/while"
)
VALID_PARSER_EXAMPLES_LOG
=
"./log/parse_valid_error.log"
>
$VALID_PARSER_EXAMPLES_LOG
for
file
in
$(
find
$VALID_EXAMPLES
-name
"*.wacc"
)
do
./compile
$file
2>>
$VALID_PARSER_EXAMPLES_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
grep
"line [0-9]*:[0-9]*"
$VALID_PARSER_EXAMPLES_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$VALID_PARSER_EXAMPLES_LOG
exit
1
fi
# counters to represent the total number of test files to be processed
TOTAL_COUNT
=
$(
find
${
VALID_EXAMPLES
[@]
}
-name
"*.wacc"
|
wc
-l
)
COUNTER
=
0
for
folder
in
${
VALID_EXAMPLES
[@]
}
;
do
for
file
in
$(
find
$folder
-name
"*.wacc"
)
do
./compile
$file
2>>
$VALID_PARSER_EXAMPLES_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
grep
"line [0-9]*:[0-9]*"
$VALID_PARSER_EXAMPLES_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$VALID_PARSER_EXAMPLES_LOG
exit
1
fi
((
COUNTER +
=
1
))
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
finished
\n
"
done
echo
"========================================================================================"
echo
"Test Folder"
$folder
"has been processed"
"(
$COUNTER
/
$((
$TOTAL_COUNT
))
)"
echo
"========================================================================================"
done
\ No newline at end of file
scripts/semanticCheckerSemanticErr
View file @
549a71f0
#!/bin/sh
INVALID_SEMANTIC_ERR
=
"./src/test/examples/invalid/semanticErr"
INVALID_CHECKER_SEMANTIC_ERR_LOG
=
"./log/checker_invalid_semantic_error.log"
INVALID_SEMANTIC_ERR
=(
"./src/test/examples/invalid/semanticErr/exit"
"./src/test/examples/invalid/semanticErr/expressions"
"./src/test/examples/invalid/semanticErr/function"
"./src/test/examples/invalid/semanticErr/if"
"./src/test/examples/invalid/semanticErr/IO"
"./src/test/examples/invalid/semanticErr/multiple"
"./src/test/examples/invalid/semanticErr/pairs"
"./src/test/examples/invalid/semanticErr/print"
"./src/test/examples/invalid/semanticErr/read"
"./src/test/examples/invalid/semanticErr/scope"
"./src/test/examples/invalid/semanticErr/variables"
"./src/test/examples/invalid/semanticErr/while"
)
INVALID_CHECKER_SEMANTIC_ERR_LOG
=
"./log/checker_invalid_semantic_error.log"
>
$INVALID_CHECKER_SEMANTIC_ERR_LOG
for
file
in
$(
find
$INVALID_SEMANTIC_ERR
-name
"*.wacc"
)
do
./compile
$file
2>>
$INVALID_CHECKER_SEMANTIC_ERR_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
200
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
!
grep
"line [0-9]*:[0-9]*"
$INVALID_CHECKER_SEMANTIC_ERR_LOG
>
/dev/null
;
then
echo
"expecting error but the following has none:"
cat
$INVALID_CHECKER_SEMANTIC_ERR_LOG
echo
$file
exit
1
fi
# counters to represent the total number of test files to be processed
TOTAL_COUNT
=
$(
find
${
INVALID_SEMANTIC_ERR
[@]
}
-name
"*.wacc"
|
wc
-l
)
COUNTER
=
0
for
folder
in
${
INVALID_SEMANTIC_ERR
[@]
}
;
do
for
file
in
$(
find
$folder
-name
"*.wacc"
)
do
./compile
$file
2>>
$INVALID_CHECKER_SEMANTIC_ERR_LOG
ret
=
$?
echo
"exit status: "
$ret
if
[
$ret
-ne
200
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
if
!
grep
"line [0-9]*:[0-9]*"
$INVALID_CHECKER_SEMANTIC_ERR_LOG
>
/dev/null
;
then
echo
"expecting error but the following has none:"
cat
$INVALID_CHECKER_SEMANTIC_ERR_LOG
echo
$file
exit
1
fi
((
COUNTER +
=
1
))
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
finished
\n
"
done
echo
"========================================================================================"
echo
"Test Folder"
$folder
"has been processed"
"(
$COUNTER
/
$((
$TOTAL_COUNT
))
)"
echo
"========================================================================================"
done
\ No newline at end of file
scripts/semanticCheckerValid
View file @
549a71f0
#!/bin/sh
VALID_EXAMPLES
=
"./src/test/examples/valid"
VALID_CHECKER_EXAMPLES_LOG
=
"./log/checker_valid_error.log"
VALID_EXAMPLES
=(
"./src/test/examples/valid/advanced"
"./src/test/examples/valid/array"
"./src/test/examples/valid/basic"
"./src/test/examples/valid/expressions"
"./src/test/examples/valid/function"
"./src/test/examples/valid/if"
"./src/test/examples/valid/IO"
"./src/test/examples/valid/pairs"
"./src/test/examples/valid/runtimeErr"
"./src/test/examples/valid/scope"
"./src/test/examples/valid/sequence"
"./src/test/examples/valid/variables"
"./src/test/examples/valid/while"
)
VALID_CHECKER_EXAMPLES_LOG
=
"./log/checker_valid_error.log"
>
$VALID_CHECKER_EXAMPLES_LOG
for
file
in
$(
find
$VALID_EXAMPLES
-name
"*.wacc"
)
do
./compile
$file
2>>
$VALID_CHECKER_EXAMPLES_LOG
ret
=
$?
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
echo
"exit code: "
$ret
if
grep
"line [0-9]*:[0-9]*"
$VALID_CHECKER_EXAMPLES_LOG
>
/dev/null
||
grep
"Exception"
$VALID_CHECKER_EXAMPLES_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$VALID_CHECKER_EXAMPLES_LOG
echo
$file
exit
1
fi
done
for
folder
in
${
VALID_EXAMPLES
[@]
}
;
do
for
file
in
$(
find
$folder
-name
"*.wacc"
)
do
./compile
$file
2>>
$VALID_CHECKER_EXAMPLES_LOG
ret
=
$?
if
[
$ret
-ne
0
]
;
then
echo
"status code incorrect: "
$ret
exit
1
fi
echo
"exit code: "
$ret
if
grep
"line [0-9]*:[0-9]*"
$VALID_CHECKER_EXAMPLES_LOG
>
/dev/null
||
grep
"Exception"
$VALID_CHECKER_EXAMPLES_LOG
>
/dev/null
;
then
echo
"expecting no error but found the following:"
cat
$VALID_CHECKER_EXAMPLES_LOG
echo
$file
exit
1
fi
((
COUNTER +
=
1
))
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
finished
\n
"
done
echo
"========================================================================================"
echo
"Test Folder"
$folder
"has been processed"
"(
$COUNTER
/
$((
$TOTAL_COUNT
))
)"
echo
"========================================================================================"
done
\ No newline at end of file
src/Compiler.java
View file @
549a71f0
import
frontend.SemanticChecker
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
...
...
@@ -14,6 +13,7 @@ import frontend.antlr.*;
import
frontend.antlr.WACCParser.ProgramContext
;
import
frontend.node.Node
;
import
frontend.utils.ParserErrorHandler
;
import
frontend.SemanticChecker
;
public
class
Compiler
{
...
...
src/README
View file @
549a71f0
TODO: write your compiler in this directory.
Important! - the
frontend.
antlr directory in this directory will be overwritten by the
Important! - the antlr directory in this directory will be overwritten by the
antlrBuild script. We heavily suggest you do not write any of your
code within the
frontend.
antlr directory.
code within the antlr directory.
src/frontend/node/TypeDeclareNode.java
View file @
549a71f0
...
...
@@ -5,8 +5,8 @@ import frontend.type.Type;
public
class
TypeDeclareNode
implements
Node
{
/**
* Represent a
frontend.
type declaration. It is neither an ExprNode nor a StatNode This class is used when
* visiting a base_type, array_type, or pair_type, and will help to determine the
frontend.
type of the
* Represent a type declaration. It is neither an ExprNode nor a StatNode This class is used when
* visiting a base_type, array_type, or pair_type, and will help to determine the type of the
* declared variable
*
* Example: int, char, bool
...
...
src/frontend/node/expr/ArrayNode.java
View file @
549a71f0
...
...
@@ -8,7 +8,7 @@ import java.util.List;
public
class
ArrayNode
extends
ExprNode
{
/**
* Represent an array. Notice that the `content` will store nodes with correct
frontend.
type, not
* Represent an array. Notice that the `content` will store nodes with correct type, not
* ArrayElemNode
* Example: [1, 2, 3, 4, 5]
*/
...
...
src/frontend/node/expr/BinopNode.java
View file @
549a71f0
...
...
@@ -6,8 +6,8 @@ import frontend.type.BasicTypeEnum;
public
class
BinopNode
extends
ExprNode
{
/**
* Represent a binary operation
frontend.
node with a left and right expression a binary operation will
* either have
frontend.
type int or bool
* Represent a binary operation node with a left and right expression a binary operation will
* either have type int or bool
*
* Example: 1 + 2, 3 * 4, 5 + (6 * 2)
*/
...
...
src/frontend/node/expr/BoolNode.java
View file @
549a71f0
...
...
@@ -6,7 +6,7 @@ import frontend.type.BasicTypeEnum;
public
class
BoolNode
extends
ExprNode
{
/**
* Represent a boolean
frontend.
node
* Represent a boolean node
* Example: true, false
*/
...
...
src/frontend/node/expr/CharNode.java
View file @
549a71f0
...
...
@@ -6,7 +6,7 @@ import frontend.type.BasicTypeEnum;
public
class
CharNode
extends
ExprNode
{
/**
* Represent a character
frontend.
node
* Represent a character node
* Example: 'a', '!', '?'