https://github.com/aggstam/flex-bison-json
Simple Flex/Bison programs to validate the syntax and perform semantic analysis to JSON files.
https://github.com/aggstam/flex-bison-json
flex-bison json language-processing
Last synced: 12 months ago
JSON representation
Simple Flex/Bison programs to validate the syntax and perform semantic analysis to JSON files.
- Host: GitHub
- URL: https://github.com/aggstam/flex-bison-json
- Owner: aggstam
- License: gpl-3.0
- Created: 2023-01-24T13:16:55.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-16T13:36:52.000Z (almost 3 years ago)
- Last Synced: 2025-01-12T20:33:34.344Z (about 1 year ago)
- Topics: flex-bison, json, language-processing
- Language: Yacc
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flex-bison-json
Simple Flex and Bison programs producing the corresponding C code to validate the syntax
and perform semantic analysis to provided JSON file.
Symbols table were kindly provided by Ilias Sakellariou.
JSON grammar definition can be found at: http://www.json.org/
Compilation and tests execution is streamline via a Makefile.
Three valid and three invalid test JSON files have been provided to play with.
## Usage
```
% make
```
Makefile can be configured to use a different test case set and/or files.
## Execution example
```
❯ make test
flex -s -o json_lexer.c json_lexer.l
bison -v -o json_parser.c json_parser.y
gcc -Iexternal json_parser.c external/jsonValidatorSymbolTable.c -o json_validator -lfl
./json_validator test_files/widget.json
Total Syntax Errors found 0
./json_validator test_files/widget_error.json
Entity:: "window" on line 8. ERROR in line 8: Entity already defined. Discarting..
Entity ("debug" : "on") Expected Type integer. ERROR in line 11: Type Missmatch!.
Entity ("height" : int) Expected Type real. ERROR in line 16: Type Missmatch!.
Entity "color" has not been declared. ERROR in line 17: Missing Declation!.
Total Syntax Errors found 0
./json_validator test_files/widget_1.json
Total Syntax Errors found 0
./json_validator test_files/widget_1_error.json
ERROR in line 10: syntax error, unexpected '{', expecting '}'.
ERROR in line 12: syntax error, unexpected T_string, expecting ':'.
Entity ("width" : real) Expected Type integer. ERROR in line 14: Type Missmatch!.
Lexical Analysis: Unexpected String! :: . in line 14.
Total Syntax Errors found 2
./json_validator test_files/menu.json
Total Syntax Errors found 0
./json_validator test_files/menu_error.json
Entity ("menuitem" : array) Expected Length 3, not 4. ERROR in line 17: Length Missmatch!.
Total Syntax Errors found 0
```