Skip to content

Commit

Permalink
Merge pull request #6 from nikhil-RGB/nn/feat/addGrammarParsing
Browse files Browse the repository at this point in the history
Nn/feat/add grammar parsing
  • Loading branch information
nikhil-RGB authored Apr 28, 2024
2 parents 33edf8d + 3c777ed commit b6c5348
Show file tree
Hide file tree
Showing 52 changed files with 295 additions and 87 deletions.
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="turing_machines"
android:label="Turing Machines"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/turingmachine.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand Down Expand Up @@ -484,7 +484,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions lib/models/Tape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import 'package:turing_machines/exceptions/action_exceptions.dart';
import 'package:turing_machines/models/Actions.dart';

class Tape {
//Initialize a Tape with a character String, and optionally, a head pointer.
Tape({required this.tape, this.pointer = 0});
//factory constructor to create custom tape for grammar parsing
factory Tape.fromString({required String input}) {
List<String> list = input.split('').map((charac) {
if (charac == " ") {
return "";
}
return charac;
}).toList();
return Tape(tape: list);
//TO-DO
}

List<String> tape = ["", "", "", "", "", "", "", "", "", ""];
int pointer = 0;
//getter function for current symbol being scanned
Expand Down Expand Up @@ -62,4 +76,15 @@ class Tape {
pointer = 0;
tape = defaultTape();
}

//Reset data associated with Tape instead of constructing a new object
void resetTo({required String input, required int pointer}) {
this.pointer = pointer;
tape = input.split('').map((charac) {
if (charac == " ") {
return "";
}
return charac;
}).toList();
}
}
4 changes: 1 addition & 3 deletions lib/models/TuringMachines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class TuringMachine {
int iterations = 0;
String initial_config;
String current_config;
//TO-DO: Remove unnecessary fields
// final List<Behaviour> behaviours;
// final List<Configuration> configurations;

final Tape tape;
late LinkedHashMap<Configuration, Behaviour> machine;
TuringMachine(List<Configuration> configurations, List<Behaviour> behaviours,
Expand Down
56 changes: 55 additions & 1 deletion lib/screens/TableScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TableScreen extends StatefulWidget {
class _TableScreenState extends State<TableScreen> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final ScrollController _scrollController = ScrollController();
final TextEditingController _input = TextEditingController();

//0->m-config,1->Scanned Symbol,2->Actions,3->f-configs
final List<TextEditingController> _controllers = [
Expand Down Expand Up @@ -84,6 +85,7 @@ class _TableScreenState extends State<TableScreen> {
IconButton(
onPressed: () {
setState(() {
_input.clear();
initialConfigValue = "NONE";
deleteValue = "NONE";
for (TextEditingController contr in _controllers) {
Expand Down Expand Up @@ -163,6 +165,8 @@ class _TableScreenState extends State<TableScreen> {
deleteDropDown(),
const Gap(20),
selectInitialConfigDropDown(),
const Gap(20),
buildStringInput(platform),
const Gap(70),
ElevatedButton(
style: ElevatedButton.styleFrom(
Expand All @@ -189,7 +193,7 @@ class _TableScreenState extends State<TableScreen> {
child: const Padding(
padding: EdgeInsets.all(15.0),
child: Text(
"Create Machine",
"Create/Resume Machine",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
Expand Down Expand Up @@ -518,4 +522,54 @@ class _TableScreenState extends State<TableScreen> {
),
);
}

//Builds a text field which inputs a String for the turing machine simulator to parse.
Widget buildStringInput(Targets platform) {
return (platform != Targets.ANDROID)
? Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("Initialize Tape with String(Optional): "),
const Gap(10),
SizedBox(
width: 250,
child: TextField(
controller: _input,
),
),
const Gap(10.0),
ElevatedButton(
onPressed: () {
printOntoTape();
},
child: Text("Print onto Tape")),
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("Tape String(Optional): "),
const Gap(8.0),
SizedBox(
width: 140,
child: TextField(
controller: _input,
),
),
const Gap(9.5),
ElevatedButton(
onPressed: () {
printOntoTape();
},
child: Text("Print onto Tape")),
],
);
}

//Fills the initialization string onto the tape.
void printOntoTape() {
widget.machine.tape.resetTo(input: _input.text, pointer: 0);
}
}
45 changes: 39 additions & 6 deletions lib/screens/TapeScreen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import 'package:turing_machines/exceptions/action_exceptions.dart';
import 'package:turing_machines/models/TuringMachines.dart';
import 'package:turing_machines/widgets/TapeWidget.dart';
import 'package:gap/gap.dart';

class TapeScreen extends StatefulWidget {
bool _followHead = true;
final TuringMachine machine;
const TapeScreen({super.key, required this.machine});
TapeScreen({super.key, required this.machine});
final double tape_cell_width = 50.0;
@override
State<TapeScreen> createState() => _TapeScreenState();
Expand Down Expand Up @@ -69,6 +72,34 @@ class _TapeScreenState extends State<TapeScreen> {
color: Colors.blue, fontWeight: FontWeight.bold),
),
const Gap(5),
SizedBox(
width: 220,
child: CheckboxListTile(
title: Text(
"Follow Head Pointer",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: (widget._followHead) ? Colors.blue : Colors.black,
),
),
value: widget._followHead,
controlAffinity: ListTileControlAffinity.leading,
secondary: Icon(
Icons.follow_the_signs,
color: (widget._followHead) ? Colors.blue : Colors.black,
),
activeColor: Colors.blue,
onChanged: (bool? val) {
if (val == null) {
return;
}
setState(() {
widget._followHead = val;
});
},
),
)
],
),
floatingActionButton: FloatingActionButton(
Expand All @@ -95,11 +126,13 @@ class _TapeScreenState extends State<TapeScreen> {
}
if (result) {
setState(() {});
_sc.animateTo(
(widget.tape_cell_width * widget.machine.tape.pointer),
duration: const Duration(milliseconds: 200),
curve: Curves.ease,
);
if (widget._followHead) {
_sc.animateTo(
(widget.tape_cell_width * widget.machine.tape.pointer),
duration: const Duration(milliseconds: 200),
curve: Curves.ease,
);
}
}
},
backgroundColor: Colors.blue,
Expand Down
2 changes: 1 addition & 1 deletion lib/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Testing {
Behaviour(actions: Actions.parseActions("R,P0"), f_config: "Q"),
];
TuringMachine machine = TuringMachine(configurations, behaviours,
tape: Tape(), initial_config: "B");
tape: Tape(tape: Tape.defaultTape()), initial_config: "B");
return machine;
}

Expand Down
132 changes: 66 additions & 66 deletions macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
{
"images" : [
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "app_icon_16.png",
"scale" : "1x"
"info": {
"version": 1,
"author": "xcode"
},
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "app_icon_32.png",
"scale" : "2x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "app_icon_32.png",
"scale" : "1x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "app_icon_64.png",
"scale" : "2x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "app_icon_128.png",
"scale" : "1x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "app_icon_256.png",
"scale" : "2x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "app_icon_256.png",
"scale" : "1x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "app_icon_512.png",
"scale" : "2x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "app_icon_512.png",
"scale" : "1x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "app_icon_1024.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
"images": [
{
"size": "16x16",
"idiom": "mac",
"filename": "app_icon_16.png",
"scale": "1x"
},
{
"size": "16x16",
"idiom": "mac",
"filename": "app_icon_32.png",
"scale": "2x"
},
{
"size": "32x32",
"idiom": "mac",
"filename": "app_icon_32.png",
"scale": "1x"
},
{
"size": "32x32",
"idiom": "mac",
"filename": "app_icon_64.png",
"scale": "2x"
},
{
"size": "128x128",
"idiom": "mac",
"filename": "app_icon_128.png",
"scale": "1x"
},
{
"size": "128x128",
"idiom": "mac",
"filename": "app_icon_256.png",
"scale": "2x"
},
{
"size": "256x256",
"idiom": "mac",
"filename": "app_icon_256.png",
"scale": "1x"
},
{
"size": "256x256",
"idiom": "mac",
"filename": "app_icon_512.png",
"scale": "2x"
},
{
"size": "512x512",
"idiom": "mac",
"filename": "app_icon_512.png",
"scale": "1x"
},
{
"size": "512x512",
"idiom": "mac",
"filename": "app_icon_1024.png",
"scale": "2x"
}
]
}
Binary file modified macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
Binary file modified macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
Binary file modified macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
Binary file modified macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
Loading

0 comments on commit b6c5348

Please sign in to comment.